#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setWindowTitle("计算器");

    QFont f("仿宋",14);
    ui->mainLineEdit->setFont(f);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_Button1_clicked()
{
    expression += "1";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button2_clicked()
{
    expression += "2";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button3_clicked()
{
    expression += "3";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button4_clicked()
{
    expression += "4";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button5_clicked()
{
    expression += "5";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button6_clicked()
{
    expression += "6";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button7_clicked()
{
    expression += "7";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button8_clicked()
{
    expression += "8";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button9_clicked()
{
    expression += "9";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_leftButton_clicked()
{
    expression += "(";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_Button0_clicked()
{
    expression += "0";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_rightButton_clicked()
{
    expression += ")";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_equalButton_clicked()
{
    expression += "=";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_divButton_clicked()
{
    expression += "/";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_multButton_clicked()
{
    expression += "*";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_subButton_clicked()
{
    expression += "-";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_addButton_clicked()
{
    expression += "+";
    ui->mainLineEdit->setText(expression);
}

void Widget::on_clearButton_clicked()
{
    expression.clear();
    ui->mainLineEdit->clear();
}

void Widget::on_delButton_clicked()
{
    expression.chop(1);//删除一个字符
    ui->mainLineEdit->setText(expression);
}
